(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('cda.popup.ppfMemberViewController', ppfMemberViewController);
	ppfMemberViewController.$inject = [ '$scope', '$q', '$uibModalInstance', 'Constants', 'dialogsModule', 'gridService', 'modalService', 'layoutConfig' , 'authService', 'ajaxServiceFactory', 'validatorConfig', 'ppfMemberService'];
	function ppfMemberViewController($scope, $q, $uibModalInstance, Constants, dialogsModule, gridService, modalService, layoutConfig, authService, ajaxServiceFactory, validatorConfig, ppfMemberService) {
		var ctrl = this, log = $scope.loggerFactory.getLogger("ppfMemberViewController"), ajaxService = ajaxServiceFactory.buildAjaxService({
		});
		ctrl.dialogsModule = dialogsModule;
//		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.ppfMember = {};
		ctrl.formName = "ppfMemberForm";
		
		ctrl.init = function() {
			// init acct
			ppfMemberService.initProfAcct(layoutConfig, $scope, ctrl);
			// init int
			//ppfMemberService.initProfInt(layoutConfig, $scope, ctrl);
			//ppfMemberService.initProfCostOfFundInt(layoutConfig, $scope, ctrl);
			// init pastdue
			ppfMemberService.initProfPastdue(layoutConfig, $scope, ctrl);
			// init fee
			ppfMemberService.initProfFee(layoutConfig, $scope, ctrl);
			// init doc
			ppfMemberService.initEventDoccfg(layoutConfig, $scope, ctrl);
			// init limit facility
			//ppfMemberService.initProfLimitFaci(layoutConfig, $scope, ctrl);
			//ppfMemberService.initProfLimitInsFaci(layoutConfig, $scope, ctrl);
			//ppfMemberService.initProfLimitPurFaci(layoutConfig, $scope, ctrl);
			// init Settlement Instruction
			ppfMemberService.initProfSetlinst(layoutConfig, $scope, ctrl);
			// init cust prop define
			ppfMemberService.initCustProp(layoutConfig, $scope, ctrl);
			//
			ppfMemberService.initGeneral($scope, ctrl).then(function() {
				var initPpfMember = ctrl.dialogsModule.params.ppfMember || {};
				initPpfMember.prodSubtypeExtProperty = ctrl.dialogsModule.params.prodSubtypeExtProperty;
				// reset data
				ppfMemberService.resetMemberByProdSubtypeExtProperty(ctrl, initPpfMember);
				//
				ppfMemberService.initLayoutConfigAndModel(ctrl, $scope, initPpfMember, "ppfMemberView").then(function() {
					ctrl.ppfMemberOld = ctrl.dialogsModule.params.ppfMemberOld;
					if (ctrl.ppfMemberOld) {
						ctrl.ppfMemberOld.profAccts = ctrl.ppfMemberOld.profAccts || [];
						ctrl.ppfMemberOld.profPastdues = ctrl.ppfMemberOld.profPastdues || [];
						ctrl.ppfMemberOld.profFees = ctrl.ppfMemberOld.profFees || [];
						ctrl.ppfMemberOld.eventDoccfgs = ctrl.ppfMemberOld.eventDoccfgs || [];
						ctrl.ppfMemberOld.profSetlinsts = ctrl.ppfMemberOld.profSetlinsts || [];
					}
					// reset cust prop data
					ctrl.resetCustProperties();
				});
			});
		};
		
		ctrl.close = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['close'] || dialogsModule.btnCallback['close']() !== false) {
				$uibModalInstance.dismiss();
			}
		};
		
	}
})(angular);
